﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using IDAL;
using Model; 

namespace DAL
{
    public class Aging:IAging
    {
        #region 静态变量
        //进箱生产操作
        private const string PARM_AGING_ID = "@AgingID";
        private const string PARM_AGING_ASSEMBLEUSERID = "@AssembleUserID";
        
        private const string PARM_AGING_PRODUCTTYPEID = "@ProductTypeID";
        private const string PARM_AGING_AMOUNT = "@Amount";
        private const string PARM_AGING_TIMESPEC = "@TimeSpec";
        private const string PARM_AGING_TEMPSPEC = "@TempSpec";
        private const string PARM_AGING_AGINGSTEP = "@AgingStep";
        private const string PARM_AGING_DEVICENAME = "@DeviceName";
        private const string PARM_AGING_ATTRIBUTES = "@Attributes";
        private const string PARM_AGING_DEPARTMENT = "@Department";
        private const string PARM_AGING_INBOXMANUUSER = "@InBoxManuUser";
        //进箱质量确认
        private const string PARM_AGING_INBOXQUALUSER = "@InBoxQualUser";
        private const string PARM_AGING_INBOXQUALAMOUNT = "@InBoxQualAmount";
        //恒温开始生产确认
        private const string PARM_AGING_TEMPSTARTMANUUSER = "@TempStartManuUser";
        //恒温开始质量确认
        private const string PARM_AGING_TEMPSTARTQUALUSER = "@TempStartQualUser";
        //生产巡查确认
        private const string PARM_AGING_PATROLMANUUSER = "@PatrolManuUser";
        //质量巡查确认
        private const string PARM_AGING_PATROLQUALUSER = "@PatrolQualUser";
        //恒温结束生产确认
        private const string PARM_AGING_ENDTEMPMANUUSER = "@TempEndManuUser";
        //恒温结束质量确认
        private const string PARM_AGING_ENDTEMPQUALUSER = "@TempEndQualUser";
        private const string PARM_AGING_ENDTEMPQUALAMOUNT = "@TempEndQualAmount";

        private const string PARM_AGING_DT = "@AgingItemdt";

        private const string PARM_AGING_PRODUCTSN = "@ProductSN";

        private const string PARM_AGING_STARTTIME = "@starttime";
        private const string PARM_AGING_STOPTIME = "@stoptime";

        private const string PARM_AGING_INBOXMANUTIME = "@InBoxManuTime";
        #endregion

        #region 产线操作相关
        public bool Aging_Insert(AgingInfo ai)
        {
            try
            {
                SqlParameter[] testParms = Get2Parameters(PARM_AGING_ASSEMBLEUSERID);
                //Bind the parameter
                testParms[0].Value = ai.AgingID;
                testParms[1].Value = ai.AssembleUserID;
                SqlCommand cmd = new SqlCommand();
                foreach (SqlParameter parm in testParms)
                    cmd.Parameters.Add(parm);
                using (SqlConnection conn = new SqlConnection(sqlHelper.ConnectionStringLocalTransaction))
                {
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "Aging_Insert";
                    using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { }
                }
                cmd.Parameters.Clear();
                return true;
            }
            catch
            {
                return false;
            }
        }//已经被代替的函数

        /*public bool AgingAndItem_Insert(AgingInfo ai, DataTable dt)
        {
            List<SqlParameter> pList = new List<SqlParameter>() {
            sqlHelper.CreateSqlParemeterStructured(PARM_AGING_DT,dt)};

            SqlParameter[] testParms = Get2Parameters(PARM_AGING_ASSEMBLEUSERID);
            testParms[0].Value = ai.AgingID;
            testParms[1].Value = ai.AssembleUserID;

            using (SqlConnection conn = new SqlConnection(sqlHelper.ConnectionStringLocalTransaction))
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();
                SqlTransaction tran = conn.BeginTransaction("SampleTransaction");
                cmd.Connection = conn;
                cmd.Transaction = tran;
                cmd.CommandType = CommandType.StoredProcedure;
                try
                {
                    foreach (SqlParameter parm in testParms)
                        cmd.Parameters.Add(parm);
                    cmd.CommandText = "Aging_Insert";
                    cmd.ExecuteNonQuery();
                    cmd.Parameters.Clear();
                    foreach (SqlParameter parm in pList)
                        cmd.Parameters.Add(parm);
                    cmd.CommandText = "AgingItem_Insert";
                    cmd.ExecuteNonQuery();
                    cmd.Parameters.Clear();
                    tran.Commit();
                    return true;
                }
                catch
                {
                    tran.Rollback();
                    return false;
                }
            }
        }*///保留此方法
        
        public bool AgingAndItem_Insert(AgingInfo ai, DataTable dt)
        {
            List<SqlParameter> pList = new List<SqlParameter>() {
            sqlHelper.CreateSqlParemeterStructured(PARM_AGING_DT,dt)};
            
            //AgingID,AssembleUserID,ProductTypeID,Amount,TimeSpec,TempSpec,AgingStep,Attributes,Department
            SqlParameter[] testParms = Get9Parameters();
            testParms[0].Value = ai.AgingID;
            testParms[1].Value = ai.AssembleUserID;
            testParms[2].Value = ai.ProductTypeID;
            testParms[3].Value = ai.Amount;
            testParms[4].Value = ai.TimeSpec;
            testParms[5].Value = ai.TempSpec;
            testParms[6].Value = ai.AgingStep;
            testParms[7].Value = ai.Attributes;
            testParms[8].Value = ai.Department;

            using (SqlConnection conn = new SqlConnection(sqlHelper.ConnectionStringLocalTransaction))
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();
                SqlTransaction tran = conn.BeginTransaction("SampleTransaction");
                cmd.Connection = conn;
                cmd.Transaction = tran;
                cmd.CommandType = CommandType.StoredProcedure;
                try
                {
                    foreach (SqlParameter parm in testParms)
                        cmd.Parameters.Add(parm);
                    cmd.CommandText = "Aging_Insert";
                    cmd.ExecuteNonQuery();
                    cmd.Parameters.Clear();
                    foreach (SqlParameter parm in pList)
                        cmd.Parameters.Add(parm);
                    cmd.CommandText = "AgingItem_Insert";
                    cmd.ExecuteNonQuery();
                    cmd.Parameters.Clear();
                    tran.Commit();
                    return true;
                }
                catch
                {
                    tran.Rollback();
                    return false;
                }
            }
        }//代替上一个注释的方法

        public bool Aging_InBoxManu(string agingID,string deviceName,string userID)
        {
            try
            {
                SqlParameter[] testParms = Get3Parameters();
                //Bind the parameter
                testParms[0].Value = agingID;
                testParms[1].Value = deviceName;
                testParms[2].Value = userID;
                SqlCommand cmd = new SqlCommand();
                foreach (SqlParameter parm in testParms)
                    cmd.Parameters.Add(parm);
                using (SqlConnection conn = new SqlConnection(sqlHelper.ConnectionStringLocalTransaction))
                {
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "Aging_InBoxManu";
                    using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { }
                }
                cmd.Parameters.Clear();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool Aging_InBoxQual(string agingID, string userID, int amount)
        {
            try
            {
                SqlParameter[] testParms = Get3Parameters(PARM_AGING_INBOXQUALUSER,PARM_AGING_INBOXQUALAMOUNT);
                //Bind the parameter
                testParms[0].Value = agingID;
                testParms[1].Value = userID;
                testParms[2].Value = amount;
                SqlCommand cmd = new SqlCommand();
                foreach (SqlParameter parm in testParms)
                    cmd.Parameters.Add(parm);
                using (SqlConnection conn = new SqlConnection(sqlHelper.ConnectionStringLocalTransaction))
                {
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "Aging_InBoxQual";
                    using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { }
                }
                cmd.Parameters.Clear();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool Aging_TempStartManu(string agingID, string userID)
        {
            try
            {
                SqlParameter[] testParms = Get2Parameters(PARM_AGING_TEMPSTARTMANUUSER);
                //Bind the parameter
                testParms[0].Value = agingID;
                testParms[1].Value = userID;
                SqlCommand cmd = new SqlCommand();
                foreach (SqlParameter parm in testParms)
                    cmd.Parameters.Add(parm);
                using (SqlConnection conn = new SqlConnection(sqlHelper.ConnectionStringLocalTransaction))
                {
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "Aging_TempStartManu";
                    using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { }
                }
                cmd.Parameters.Clear();
                return true;
            }
            catch
            {
                return false;
            }      
        }

        public bool Aging_TempStartQual(string agingID, string userID)
        {
            try
            {
                SqlParameter[] testParms = Get2Parameters(PARM_AGING_TEMPSTARTQUALUSER);
                //Bind the parameter
                testParms[0].Value = agingID;
                testParms[1].Value = userID;
                SqlCommand cmd = new SqlCommand();
                foreach (SqlParameter parm in testParms)
                    cmd.Parameters.Add(parm);
                using (SqlConnection conn = new SqlConnection(sqlHelper.ConnectionStringLocalTransaction))
                {
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "Aging_TempStartQual";
                    using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { }
                }
                cmd.Parameters.Clear();
                return true;
            }
            catch
            {
                return false;
            } 
        }

        public bool Aging_PatrolManu(string agingID, string userID)
        {
            try
            {
                SqlParameter[] testParms = Get2Parameters(PARM_AGING_PATROLMANUUSER);
                //Bind the parameter
                testParms[0].Value = agingID;
                testParms[1].Value = userID;
                SqlCommand cmd = new SqlCommand();
                foreach (SqlParameter parm in testParms)
                    cmd.Parameters.Add(parm);
                using (SqlConnection conn = new SqlConnection(sqlHelper.ConnectionStringLocalTransaction))
                {
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "Aging_PatrolManu";
                    using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { }
                }
                cmd.Parameters.Clear();
                return true;
            }
            catch
            {
                return false;
            } 
        }

        public bool Aging_PatrolQual(string agingID, string userID) 
        {
            try
            {
                SqlParameter[] testParms = Get2Parameters(PARM_AGING_PATROLQUALUSER);
                //Bind the parameter
                testParms[0].Value = agingID;
                testParms[1].Value = userID;
                SqlCommand cmd = new SqlCommand();
                foreach (SqlParameter parm in testParms)
                    cmd.Parameters.Add(parm);
                using (SqlConnection conn = new SqlConnection(sqlHelper.ConnectionStringLocalTransaction))
                {
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "Aging_PatrolQual";
                    using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { }
                }
                cmd.Parameters.Clear();
                return true;
            }
            catch
            {
                return false;
            } 
        }

        public bool Aging_TempEndManu(string agingID, string userID)
        {
            try
            {
                SqlParameter[] testParms = Get2Parameters(PARM_AGING_ENDTEMPMANUUSER);
                //Bind the parameter
                testParms[0].Value = agingID;
                testParms[1].Value = userID;
                SqlCommand cmd = new SqlCommand();
                foreach (SqlParameter parm in testParms)
                    cmd.Parameters.Add(parm);
                using (SqlConnection conn = new SqlConnection(sqlHelper.ConnectionStringLocalTransaction))
                {
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "Aging_TempEndManu";
                    using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { }
                }
                cmd.Parameters.Clear();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool Aging_TempEndQual(string agingID, string userID, int amount)
        {
            try
            {
                SqlParameter[] testParms = Get3Parameters(PARM_AGING_ENDTEMPQUALUSER, PARM_AGING_ENDTEMPQUALAMOUNT);
                //Bind the parameter
                testParms[0].Value = agingID;
                testParms[1].Value = userID;
                testParms[2].Value = amount;
                SqlCommand cmd = new SqlCommand();
                foreach (SqlParameter parm in testParms)
                    cmd.Parameters.Add(parm);
                using (SqlConnection conn = new SqlConnection(sqlHelper.ConnectionStringLocalTransaction))
                {
                    conn.Open();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "Aging_TempEndQual";
                    using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { }
                }
                cmd.Parameters.Clear();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        //-------------------------以上为时效数据写入，以下为时效数据检出-----------------------------------------------
        #region 时效数据检出
        public bool Aging_ExistsID(string agingID)
        {
            SqlParameter parm = new SqlParameter(PARM_AGING_ID, SqlDbType.NVarChar, 50);
            //Bind the parameter
            parm.Value = agingID;
            int n = Convert.ToInt32(sqlHelper.ExecuteScalar(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "Aging_ExistsID", parm));
            return Convert.ToBoolean(n);
        }

        public bool Aging_ExistsValidID(string agingID)
        {
            SqlParameter parm = new SqlParameter(PARM_AGING_ID, SqlDbType.NVarChar, 50);
            //Bind the parameter
            parm.Value = agingID;
            int n = Convert.ToInt32(sqlHelper.ExecuteScalar(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "Aging_ExistsValidID", parm));
            return Convert.ToBoolean(n);
        }

        public string Aging_IsSecondAgingOK(DataTable dt)
        {
            SqlParameter parm = sqlHelper.CreateSqlParemeterStructured(PARM_AGING_DT, dt);

            string str = Convert.ToString(sqlHelper.ExecuteScalar(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "Aging_IsSecondAgingOK", parm));
            return str;
        }


        public string Aging_HasValidPostStep(string productTypeID, DataTable dt)
        {
            SqlParameter parm = new SqlParameter(PARM_AGING_PRODUCTTYPEID, SqlDbType.NVarChar, 50);
            parm.Value = productTypeID;
            SqlParameter parm1 = sqlHelper.CreateSqlParemeterStructured(PARM_AGING_DT, dt);

            SqlParameter[] parms = new SqlParameter[] { parm, parm1 };
            string str = Convert.ToString(sqlHelper.ExecuteScalar(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "Aging_HasValidPostStep", parms));
            return str;
        }

        
        public AgingInfo GetbyAgingID(string agingID)
        {
            AgingInfo test;
            //Create a parameter    
            SqlParameter parm = new SqlParameter(PARM_AGING_ID, SqlDbType.NVarChar, 50);
            //Bind the parameter
            parm.Value = agingID;

            //Execute the query	
            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "Aging_SelectbyAgingID", parm))
            {
                if (rdr.Read())
                    test = new AgingInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetValue(2).ToString(),
                        rdr.GetInt32(3), rdr.GetDecimal(4), rdr.GetInt32(5), rdr.GetValue(6).ToString(), rdr.GetValue(7).ToString(),
                        rdr.GetValue(8).ToString(), rdr.GetValue(9).ToString(), rdr.GetDateTime(10), rdr.GetValue(11).ToString(),
                        rdr.GetDateTime(12), rdr.GetValue(13).ToString(), rdr.GetInt32(14), rdr.GetDateTime(15), rdr.GetValue(16).ToString(),
                        rdr.GetDateTime(17), rdr.GetValue(18).ToString(), rdr.GetDateTime(19), rdr.GetValue(20).ToString(),
                        rdr.GetDateTime(21), rdr.GetValue(22).ToString(), rdr.GetDateTime(23), rdr.GetValue(24).ToString(),
                        rdr.GetDateTime(25), rdr.GetValue(26).ToString(), rdr.GetInt32(27), rdr.GetValue(28).ToString());
                else
                    test = new AgingInfo();
            }
            return test;
        }

        public AgingInfo GetbyDeviceName(string deviceName)
        {
            AgingInfo test;
            //Create a parameter    
            SqlParameter parm = new SqlParameter(PARM_AGING_DEVICENAME, SqlDbType.NVarChar, 10);
            //Bind the parameter
            parm.Value = deviceName;

            //Execute the query	
            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "Aging_LastbyDeviceName", parm))
            {
                if (rdr.Read())
                    test = new AgingInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetValue(2).ToString(),
                        rdr.GetInt32(3), rdr.GetDecimal(4), rdr.GetInt32(5), rdr.GetValue(6).ToString(), rdr.GetValue(7).ToString(),
                        rdr.GetValue(8).ToString(), rdr.GetValue(9).ToString(), rdr.GetDateTime(10), rdr.GetValue(11).ToString(),
                        rdr.GetDateTime(12), rdr.GetValue(13).ToString(), rdr.GetInt32(14), rdr.GetDateTime(15), rdr.GetValue(16).ToString(),
                        rdr.GetDateTime(17), rdr.GetValue(18).ToString(), rdr.GetDateTime(19), rdr.GetValue(20).ToString(),
                        rdr.GetDateTime(21), rdr.GetValue(22).ToString(), rdr.GetDateTime(23), rdr.GetValue(24).ToString(),
                        rdr.GetDateTime(25), rdr.GetValue(26).ToString(), rdr.GetInt32(27), rdr.GetValue(28).ToString());
                else
                    test = new AgingInfo();
            }
            return test;
        }

        public IList<string> GetIDsbyDeviceName(string deviceName, DateTime dt)
        {
            IList<string> tests = new List<string>();

            SqlParameter[] testParms = GetDVDTParameters();
            //Bind the parameter
            testParms[0].Value = deviceName;
            testParms[1].Value = dt;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "Aging_LastIDsbyDeviceName", testParms))
            {
                while (rdr.Read())
                {
                    string test = rdr.GetValue(0).ToString();
                    tests.Add(test);
                }
            }
            return tests;
        }

        public AgingInfo GetAging_InBox(string agingID)
        {
            AgingInfo test;
            //Create a parameter    
            SqlParameter parm = new SqlParameter(PARM_AGING_ID, SqlDbType.NVarChar, 50);
            //Bind the parameter
            parm.Value = agingID;

            //Execute the query	
            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "Aging_Select_InBox", parm))
            {
                if (rdr.Read())
                    test = new AgingInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetInt32(2),
                        rdr.GetDecimal(3), rdr.GetInt32(4), rdr.GetValue(5).ToString(), rdr.GetValue(6).ToString(),
                        rdr.GetValue(7).ToString(), rdr.GetValue(8).ToString(), Convert.ToDateTime(rdr[9].ToString()), rdr.GetValue(10).ToString());
                else
                    test = new AgingInfo();
            }
            return test;
        }

        public IList<AgingInfo> GetLatestAgings()
        {
            IList<AgingInfo> tests = new List<AgingInfo>();

            //Execute a query to read the categories
            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "Aging_SelectbyLastDay", null))
            {
                while (rdr.Read())
                {
                    AgingInfo test = new AgingInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetInt32(2), 
                        rdr.GetDecimal(3), rdr.GetInt32(4), rdr.GetValue(5).ToString(), rdr.GetValue(6).ToString(),
                        rdr.GetValue(7).ToString(), rdr.GetValue(8).ToString(), Convert.ToDateTime(rdr[9].ToString()), rdr.GetValue(10).ToString());
                    tests.Add(test);
                }
            }
            return tests;
        }

        public IList<AgingInfo> GetAgingsbyDT(DateTime starttime, DateTime stoptime)
        {
            IList<AgingInfo> tests = new List<AgingInfo>();

            SqlParameter[] testParms = GetDTParameters();
            //Bind the parameter
            testParms[0].Value = starttime;
            testParms[1].Value = stoptime;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "Aging_SelectbyDT", testParms))
            {
                while (rdr.Read())
                {
                    AgingInfo test = new AgingInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetInt32(2),
                        rdr.GetDecimal(3), rdr.GetInt32(4), rdr.GetValue(5).ToString(), rdr.GetValue(6).ToString(),
                        rdr.GetValue(7).ToString(), rdr.GetValue(8).ToString(), Convert.ToDateTime(rdr[9].ToString()), rdr.GetValue(10).ToString());
                    tests.Add(test);
                }
            }
            return tests;
        }

        public IList<AgingInfo> GetAgingsbySN(string productSN)
        {
            IList<AgingInfo> tests = new List<AgingInfo>();

            SqlParameter parm = new SqlParameter(PARM_AGING_PRODUCTSN, SqlDbType.NVarChar, 50);
            parm.Value = productSN;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "Aging_SelectbySN", parm))
            {
                while (rdr.Read())
                {
                    AgingInfo test = new AgingInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetInt32(2),
                        rdr.GetDecimal(3), rdr.GetInt32(4), rdr.GetValue(5).ToString(), rdr.GetValue(6).ToString(),
                        rdr.GetValue(7).ToString(), rdr.GetValue(8).ToString(), Convert.ToDateTime(rdr[9].ToString()), 
                        rdr.GetValue(10).ToString(),rdr.GetValue(11).ToString());
                    tests.Add(test);
                }
            }
            return tests;
        }

        //用于获取包装前外观检验工序数据录入功能中S代码的SP
        public IList<AgingInfo> GetPassAgingsbySN(string productSN)
        {
            IList<AgingInfo> tests = new List<AgingInfo>();

            SqlParameter parm = new SqlParameter(PARM_AGING_PRODUCTSN, SqlDbType.NVarChar, 50);
            parm.Value = productSN;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "Aging_SelectPassbySN", parm))
            {
                while (rdr.Read())
                {
                    AgingInfo test = new AgingInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetInt32(2),
                        rdr.GetDecimal(3), rdr.GetInt32(4), rdr.GetValue(5).ToString(), rdr.GetValue(6).ToString(),
                        rdr.GetValue(7).ToString(), rdr.GetValue(8).ToString(), Convert.ToDateTime(rdr[9].ToString()),
                        rdr.GetValue(10).ToString(), rdr.GetValue(11).ToString());
                    tests.Add(test);
                }
            }
            return tests;
        }

        public string GetIDbySN(string productSN, string agingStep)
        {
            SqlParameter[] testParms = Get2Parameters(PARM_AGING_PRODUCTSN, PARM_AGING_AGINGSTEP);
            //Bind the parameter
            testParms[0].Value = productSN;
            testParms[1].Value = agingStep;

            string str = Convert.ToString(sqlHelper.ExecuteScalar(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "AgingID_SelectbySN", testParms));
            return str;
        }
        #endregion

        //-------------------------ADO.NET参数部分----------------------------------------------------------------------
        #region 参数部分
        private static SqlParameter[] Get2Parameters(string UserID)
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_AGING_ID, SqlDbType.NVarChar, 50),
					new SqlParameter(UserID, SqlDbType.NVarChar, 10)
                };
            return parms;
        }

        private static SqlParameter[] GetDTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_AGING_STARTTIME, SqlDbType.DateTime, 8),
					new SqlParameter(PARM_AGING_STOPTIME, SqlDbType.DateTime, 8)
                };
            return parms;
        }

        private static SqlParameter[] GetDVDTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_AGING_DEVICENAME, SqlDbType.NVarChar, 10),
					new SqlParameter(PARM_AGING_INBOXMANUTIME, SqlDbType.DateTime, 8)
                };
            return parms;
        }

        private static SqlParameter[] Get2Parameters(string productSN,string agingStep)
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(productSN, SqlDbType.NVarChar, 50),
					new SqlParameter(agingStep, SqlDbType.NVarChar, 10)
                };
            return parms;
        }
        
        private static SqlParameter[] Get3Parameters(string UserID,string Amount)
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_AGING_ID, SqlDbType.NVarChar, 50),
					new SqlParameter(UserID, SqlDbType.NVarChar, 10),
                    new SqlParameter(Amount,SqlDbType.Int,4)                
                };
            return parms;
        }

        private static SqlParameter[] Get3Parameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_AGING_ID, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_AGING_DEVICENAME, SqlDbType.NVarChar, 10),
                    new SqlParameter(PARM_AGING_INBOXMANUUSER,SqlDbType.NVarChar, 10)                
                };
            return parms;
        } 

        /*private static SqlParameter[] Get10Parameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_AGING_ID, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_AGING_PRODUCTTYPEID, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_AGING_AMOUNT, SqlDbType.Int, 4),
					new SqlParameter(PARM_AGING_TIMESPEC, SqlDbType.Decimal, 4),
                    new SqlParameter(PARM_AGING_TEMPSPEC, SqlDbType.Int, 4),
					new SqlParameter(PARM_AGING_AGINGSTEP, SqlDbType.NVarChar, 10),
                    new SqlParameter(PARM_AGING_DEVICENAME, SqlDbType.NVarChar, 10),
					new SqlParameter(PARM_AGING_ATTRIBUTES, SqlDbType.NVarChar, 10),
                    new SqlParameter(PARM_AGING_DEPARTMENT, SqlDbType.NVarChar, 10),
					new SqlParameter(PARM_AGING_INBOXMANUUSER, SqlDbType.NVarChar, 10)
                };
            return parms;
        }*///保留此方法

        //AgingID,AssembleUserID,ProductTypeID,Amount,TimeSpec,TempSpec,AgingStep,Attributes,Department
        private static SqlParameter[] Get9Parameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_AGING_ID, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_AGING_ASSEMBLEUSERID, SqlDbType.NVarChar, 10),
					new SqlParameter(PARM_AGING_PRODUCTTYPEID, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_AGING_AMOUNT, SqlDbType.Int, 4),
					new SqlParameter(PARM_AGING_TIMESPEC, SqlDbType.Decimal, 4),
                    new SqlParameter(PARM_AGING_TEMPSPEC, SqlDbType.Int, 4),
					new SqlParameter(PARM_AGING_AGINGSTEP, SqlDbType.NVarChar, 10),
					new SqlParameter(PARM_AGING_ATTRIBUTES, SqlDbType.NVarChar, 10),
                    new SqlParameter(PARM_AGING_DEPARTMENT, SqlDbType.NVarChar, 10)
                };
            return parms;
        }//代替上一个注释的方法
        #endregion
    }
}
